package irri.soils.ssnm;

import irri.soils.ssnm.R;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.TextView;

public class ActivityP extends SSNM implements View.OnClickListener{
	
	private Button button1;
	private int option;
	private Bundle b;
	private RadioButton radio1;
	private RadioButton radio2;

	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.p);
        setCustomTitle();
        b = this.getIntent().getExtras();
        int i = b.getInt("season");
        TextView tv = (TextView) findViewById(R.id.question);
        tv.setText(get("water0"));
        
        int crop = b.getInt("crop");
        String sea = "";
        if(crop<3) sea = i==1 ? get("season1") : 
        	get("season3");
        else sea = (i==1 ? (get("early")+" "+get("wet")) : 
        	(i==2 ? (get("late")+" "+get("wet")) : get("dry"))) + 
        	(SSNM.d==0 ? " season" : "");
        
        tv.setText(tv.getText()+" "+(b.getInt("irrig")<3||b.getInt("crop")==2 ? 
        		(get("water01")+" "+sea) : "")+" "+get("water02"));
        
        radio1 = (RadioButton) findViewById(R.id.radio1);
        radio1.setOnClickListener(this);
        radio2 = (RadioButton) findViewById(R.id.radio2);
        radio2.setOnClickListener(this);
        if(b.getInt("irrig")<3)
        radio1.setText(get("water1"));
        radio2.setText(get("water2")+" "+(b.getInt("irrig")<3 ? get("water21") :
        	get("water22")));
        button1 = (Button) findViewById(R.id.button1);
        button1.setOnClickListener(this);
        button1.setEnabled(false);

        if(b.containsKey("water")){
	        switch(b.getInt("water")){
	        case 1: radio1.performClick(); break;
	        case 2: radio2.performClick(); break;
	        }
        }
    }       

	@Override
	public void onClick(View v) {
		switch(v.getId()){
		case R.id.radio1: option = 1; button1.setEnabled(true); break;
		case R.id.radio2: option = 2; button1.setEnabled(true); break;
		case R.id.button1:
			Intent intent = new Intent(ActivityP.this,ActivityR.class);
			Bundle b = this.getIntent().getExtras();
			b.putInt("water", option);
			intent.putExtras(b);
			startActivity(intent);
			finish();
			break;
		}
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		if(radio1.isChecked()) radio1.performClick();
		if(radio2.isChecked()) radio2.performClick();
	}
	
	@Override
	public void onBackPressed() {
		Intent intent = new Intent(ActivityP.this, ActivityO.class);
		intent.putExtras(b);
		startActivity(intent);
		finish();
	}
}